from django.shortcuts import render
from visualization.models import playerLog
from login.middlewares import getEmail
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect

# Create your views here.
def gobang(request):
    email=getEmail(request)
    if email==None:
        return HttpResponseRedirect('/login/')
    return render(request,'gobang.html')

def battle(request,roomID):
    email=getEmail(request)
    if email==None:
        return HttpResponseRedirect('/login/')
    # log=playerLog.objects.filter(email=email)
    # log.update(plays=log[0].plays+1)
    # print('battle,roomID',roomID)
    return render(request,'gobang.html',{'title':'battle','roomID':roomID})

def witness(request,roomID):
    email=getEmail(request)
    if email==None:
        return HttpResponseRedirect('/login/')
    # log=playerLog.objects.filter(email=email)
    # log.update(witness=log[0].witness+1)
    # print('witness,roomID',roomID)
    return render(request,'witness.html',{'title':'witness','roomID':roomID})

def create(request,roomID):
    # print('create',roomID)
    return render(request,'gobang.html',{'title':'battle','roomID':roomID})